/**
 * 工具类
 */
import Vue from 'vue'
import CryptoJS from 'crypto-js'
export default {
  //aes加密
  encryption (pas,key) {
      key = CryptoJS.enc.Latin1.parse(key)
      var iv = key
      // 加密
      var encrypted = CryptoJS.AES.encrypt(
        pas,
        key, {
          iv: iv,
          mode: CryptoJS.mode.CBC,
          padding: CryptoJS.pad.Pkcs7
        })
        return encrypted.toString()
  },
  //aes解密
  decrypt(word, keyStr){  
    keyStr = keyStr ? keyStr : 'abcdefgabcdefg12';
    var key  = CryptoJS.enc.Utf8.parse(keyStr);//Latin1 w8m31+Yy/Nw6thPsMpO5fg==
    var iv = key
    var decrypt = CryptoJS.AES.decrypt(word, key, {mode:CryptoJS.mode.CBC,padding: CryptoJS.pad.Pkcs7, iv: iv,});
    return CryptoJS.enc.Utf8.stringify(decrypt).toString();
  }
}
